package com.andaily.domain.account;

import com.andaily.domain.AbstractDomain;
import com.andaily.domain.dto.account.AccountFormDTO;
import com.andaily.domain.shared.DateUtils;
import com.andaily.domain.user.User;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author Shengzhao Li
 */
public class Account extends AbstractDomain {

    /**
     * Income or Expenditure, default is Expenditure.
     */
    protected AccountKind kind = AccountKind.EXPENDITURE;

    protected AccountType type;

    protected BigDecimal amount;
    protected Date accountDate;
    protected String description;
    protected User owner;

    /**
     * Label the Account have restored or not(after logic delete it).
     */
    protected boolean restored = false;

    protected Date lastUpdateDate = DateUtils.now();

    public Account() {
    }

    public Account(BigDecimal amount, AccountType type, Date accountDate, String description) {
        this.amount = amount;
        this.type = type;
        this.accountDate = accountDate;
        this.description = description;
    }

    public AccountKind kind() {
        return kind;
    }

    public BigDecimal amount() {
        return amount;
    }

    public Date accountDate() {
        return accountDate;
    }

    public String description() {
        return description;
    }

    public AccountType type() {
        return type;
    }

    public Account owner(User owner) {
        this.owner = owner;
        return this;
    }

    public void update(AccountFormDTO accountFormDTO, AccountType accountType) {
        this.amount = new BigDecimal(accountFormDTO.getAmount());
        this.accountDate = DateUtils.getDate(accountFormDTO.getAccountDate());
        this.description = accountFormDTO.getDescription();
        this.type = accountType;
        this.lastUpdateDate = DateUtils.now();
    }

    public User owner() {
        return owner;
    }

    public boolean restored() {
        return restored;
    }

    public Date lastUpdateDate() {
        return lastUpdateDate;
    }

    public void kind(AccountKind kind) {
        this.kind = kind;
    }
}
